/**
 * Created by Toma on 2016/9/14.
 */

"use strict";
// 存入历史
var state = {
  push: function (title, query) {
    document.title = title;
    history.pushState({title: title}, title, '?' + query);
  },
  pop: function (callback) {
    window.addEventListener('popstate', function () {
      callback();
    });
  }
};


[].forEach.call(document.querySelectorAll('.link'), i => i.addEventListener('click', function (e) {
  e.preventDefault();
  var query = this.href.split('?')[1]
  var title = 'Js跳转--' + this.innerHTML;
  document.title = title;
  history.pushState({title: title}, title, '?' + query);
}));

state.pop(function () {
  console.log(history.state);
});
